import com.dmotiko.general.*

class LoaderClip 
extends BaseClip {
		
	private var mcLoad:MovieClip;
	private var mcMask:MovieClip; //mc with 100 frames
	private var txtPercent:TextField;
	private var mcController:MovieClip;
	
	private function LoaderClip(){
		mcController = this.createEmptyMovieClip("mcController", this.getNextHighestDepth());
		mcLoad.setMask(mcMask);
	}
	
	public function setPos(nPos:Number){
		setData(nPos);
		var root:LoaderClip = this;
		mcController.onEnterFrame = function(){
			var nPer:Number = root.mcMask._currentframe * 100 / root.mcMask._totalframes;
			nPer = Math.round(nPer);
			root.txtPercent.text = nPer.toString();
			//trace("LoaderClip " + root.mcMask + "._currentFrame= " + root.mcMask._currentframe + " (" + nPer + " | nPos= " + nPos + ")");
			if (nPos == 0) {
				delete this.onEnterFrame;
				root.mcMask.gotoAndStop(1);
				return;
			}
			if(nPer >= nPos){
				delete this.onEnterFrame;
				if(nPos == 100){
					root.dispatchEvent( { type: BaseClipEvent.CHANGED, target: root, pos: nPos });
				}
			} else {
				root.mcMask.nextFrame();
			}
		}
	}
	
}